/**
 * TMP001显示
 * */


var formList = {
    gname: '',
    gcode: '',
    shopCode: '',
    describe: '',
    img: '',
    price: 0,
    num: 0,
    code: '',
    showCode: '',
    visitNum: 0,
    useNum: 0,
    follow: 0,
    isfollow: 0,
}; //商品数据
var adList = {}; //广告
var commentList = []; //评论数据
var followList = []; //关注数据


/**
 * 获取门店
 * */
function getOne(){
    //if (token == '') {
    //    msgPop({msg: '没有登录'});
    //    setTimeout(function(){
    //        window.location.href = '/login.html?code=' + code;
    //    }, 1000);
    //    return
    //}
    if (code == '' || code == undefined) {
        msgPop({msg: '码值错误'});
        return
    }
    var formData = {
        token: token,
        code: code,
    };
    $.ajax({
        type: apis.goods1One.method,
        url: apis.goods1One.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg});
                return
            }
            formList = res.data;
            followList = res.data.followList;
            commentList = res.data.commentList;
            adList = res.data.ad;
            showHtml();
            getAdvert();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//场景拼接字符串
function showHtml(){
    var h = '', i;
    //图片
    h += '<style type="text/css"> #showImgOut {width: ' + cw + 'px; height: ' + cw * 0.5 + 'px; overflow: hidden;} #showImgOut img {width: ' + cw + 'px;} #followBtn {padding: 3px 10px; border: 1px solid #0088cc; color: #0088cc; border-radius: 5px;} </style>';
    h += '<div id="showImgOut">';
    if (formList.img != '') {
        h += '<img src="' + formList.img + '"/>';
        h += '<div id="showImgMore" onclick="bigImgs();">点击更多</div>';
    } else {
        h += '<div style="width: 100%; height: 100%; background: #555;"></div>';
    }
    h += '</div>';
    h += '<table>';
    h += '<tr>';
    h += '<td colspan="2" style="text-align: center;">';
    h += '<span id="followBtn" onclick="setFollow();">';
    if (formList.isfollow == 0) {
        h += '未关注？点击关注';
    } else {
        h += '已关注？点击取消';
    }
    h += '</span>';
    h += '</td>';
    h += '<tr>';
    h += '<td class="tl">商品名称</td>';
    h += '<td class="tr">' + formList.gname + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">商品编号</td>';
    h += '<td class="tr">' + formList.gcode + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">门店编号</td>';
    h += '<td class="tr">' + formList.shop_code + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">商品描述</td>';
    h += '<td class="tr">' + formList.describe + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">商品单价</td>';
    h += '<td class="tr">' + formList.price + ' 元</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">商品数量</td>';
    h += '<td class="tr">' + formList.num + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">码编号</td>';
    h += '<td class="tr">' + formList.showCode + '</td>';
    h += '</tr>';
    h += '</table>';
    //流量
    h += '<br/>';
    h += '<table>';
    h += '<tr>';
    h += '<td class="tl">订单量</td>';
    h += '<td class="tr">0</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">关注量</td>';
    h += '<td class="tr">' + formList.followTotal + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">评论量</td>';
    h += '<td class="tr">' + formList.commentTotal + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">访问量</td>';
    h += '<td class="tr">' + formList.visitNum + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">使用量</td>';
    h += '<td class="tr">' + formList.useNum + '</td>';
    h += '</tr>';
    h += '</table>';
    $('#form').html(h);
    getOrderHtml();
    getFollowHtml();
    getCommentHtml();
}


//关注设置
function setFollow(){
    if (code == '') {
        msgPop({msg: '门店错误'});
        return
    }
    if (token == '') {
        msgPop({msg: '没有登录'});
        setTimeout(function(){
            window.location.href = '/login.html?code=' + code;
        }, 1000);
        return
    }
    var formData = {
        token: token,
        code: code,
    };
    $.ajax({
        type: apis.goods1FollowSet.method,
        url: apis.goods1FollowSet.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            if (formList.isfollow == 0) {
                msgPop({msg: '关注成功'});
            } else {
                msgPop({msg: '取关成功'});
            }
            window.location.reload();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//广告位
function getAdvert(){
    //var h = '<img src="' + domain + '/videos/2024/20240202.png" style="width: 100%; opacity: 0.2;"/>';
    var h = '<img src="' + adList.link + '"/>';
    $('#advert').html(h);
}


//订单HTML
function getOrderHtml(){
    var h = '', i;
    h += '<div class="title">';
    h += '订单 ';
    h += '<span class="small">（0）</span>';
    h += '</div>';
    h += '<table>';
    h += '<tr>';
    h += '<td class="tl">用户</td>';
    h += '<td class="tr">00000</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">关注时间</td>';
    h += '<td class="tr">00000</td>';
    h += '</tr>';
    h += '</table>';
    h += '<table>';
    h += '<tr>';
    h += '<td class="tl">用户</td>';
    h += '<td class="tr">00000</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">关注时间</td>';
    h += '<td class="tr">00000</td>';
    h += '</tr>';
    h += '</table>';
    $('#order').html(h);
}


//关注HTML
function getFollowHtml(){
    var h = '', i;
    h += '<div class="title">';
    h += '关注 ';
    h += '<span class="small">（' + formList.follow + '）</span>';
    h += '</div>';
    //h += '<table>';
    //h += '<tr>';
    //h += '<td class="tl">用户</td>';
    //h += '<td class="tr">00000</td>';
    //h += '</tr>';
    //h += '<tr>';
    //h += '<td class="tl">关注时间</td>';
    //h += '<td class="tr">00000</td>';
    //h += '</tr>';
    //h += '</table>';
    //h += '<table>';
    //h += '<tr>';
    //h += '<td class="tl">用户</td>';
    //h += '<td class="tr">00000</td>';
    //h += '</tr>';
    //h += '<tr>';
    //h += '<td class="tl">关注时间</td>';
    //h += '<td class="tr">00000</td>';
    //h += '</tr>';
    //h += '</table>';
    var uid, addtimes, gcode;
    for (i = 0; i < followList.length; i ++) {
        uid = followList[i].uid;
        gcode = followList[i].gcode;
        addtimes = followList[i].addtime.split(' ');
        h += '<table>';
        h += '<tr>';
        h += '<td class="tl">用户</td>';
        h += '<td class="tr">' + uid + '</td>';
        h += '</tr>';
        h += '<tr>';
        h += '<td class="tl">关注时间</td>';
        h += '<td class="gtr">' + addtimes[0] + '</td>';
        h += '</tr>';
        h += '</table>';
    }
    $('#follow').html(h);
}


//评论HTML
function getCommentHtml(){
    var h = '';
    h += '<div class="title">';
    h += '评论 ';
    h += '<span class="small">（0）</span>';
    h += '</div>';
    h += '<table>';
    h += '<tr>';
    h += '<td class="tl">用户</td>';
    h += '<td class="tr">00000</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">评论内容</td>';
    h += '<td class="tr">00000</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">评论时间</td>';
    h += '<td class="tr">00000</td>';
    h += '</tr>';
    h += '</table>';
    h += '<table>';
    h += '<tr>';
    h += '<td class="tl">用户</td>';
    h += '<td class="tr">00000</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">评论内容</td>';
    h += '<td class="tr">00000</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="tl">评论时间</td>';
    h += '<td class="tr">00000</td>';
    h += '</tr>';
    h += '</table>';
    //var userInfo = getUserInfo();
    //var h = '', id, addDates, sender, accept;
    //for (var i = 0; i < commentList.length; i ++) {
    //    h += '<tr>';
    //    h += '<td class="pl-l">';
    //    h += '<img src="../../../imgs/mpPlay.png"/>';
    //    h += '<div>' + strSuffix(sender, 5) + '</div>';
    //    h += '</td>';
    //    h += '<td class="pl-r" onclick="aiteComment(' + id + ');">';
    //    h += '<div>';
    //    h += '对<b id="accept-' + id + '">';
    //    h += userInfo.uid == sender ? '版主' : strSuffix(sender, 6);
    //    h += '</b>：';
    //    h += '<span style="color: #ccc; float: right;">' + addDates[0] + '</span>';
    //    h += '</div>';
    //    h += '<div style="width: ' + (cw * 1 - 80) + 'px; max-height: 50px; word-wrap: break-word; overflow: hidden;">' + d[i].content + '</div>';
    //    h += '</td>';
    //    h += '</tr>';
    //}
    $('#comment').html(h);
}


//设置广告使用
function adUse(){
    //if (token == '') {
    //    msgPop({msg: '没有登录'});
    //    setTimeout(function(){
    //        window.location.href = '/login.html?code=' + code;
    //    }, 1000);
    //    return
    //}
    var formData = {
        token: token,
        adid: adList.adid,
        useid: adList.useid
    };
    $.ajax({
        type: apis.tmp1AdUse.method,
        url: apis.tmp1AdUse.url,
        data: formData,
        success: function (res) {
            console.log(res);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}